package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.Tr;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class TrDao {

	private DBHelp<Tr> db = new DBHelp<Tr>();

	public Tr findByTrName(String trname) {
		String sql = "select id ,trname,tel from t_tr where trname=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), trname);
	}

	public Tr findByTrId(String trId) {
		String sql = "select id ,trname,tel from t_tr where id=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), trId);
	}

	public void save(String trid, String trname, String tel) {
		String sql = "insert into t_tr(id, trname,tel) values(?,?,?)";
		db.executeSQL(sql, trid, trname, tel);
	}

	private class CompRowMapper implements RowMapper<Tr> {

		public Tr mapperRow(ResultSet rs) throws SQLException {

			Tr tr = new Tr();
			tr.setId(rs.getString("id"));
			tr.setTrname(rs.getString("trname"));
			tr.setTel(rs.getString("tel"));

			return tr;
		}

	}

}
